{include file="public/header" /}
<form class="layui-form">
    <div class="layui-form-item">
        <input type="hidden" name="__token__" value="{:token()}" />
        <input type="hidden" class="layui-input" name="id" value="{$group['id']}">
        <label class="layui-form-label">部门名</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="name" placeholder="请输入部门名" value="{$group['name']}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限菜单</label>
        <div class="layui-input-block">
            {foreach($menu as $item)}
                <input type="checkbox" name="menus[{$item.id}]" lay-skin="primary" title="{$item.name}" {:isset( $group.authority) && in_array($item.id, $group.authority) ? "checked" : ""}>            
                <hr>
                {if (isset($item['children']) && $item['children'])}
                    {volist name="$item.children" id="vo"}
                        <input type="checkbox" name="menus[{$vo.id}]" lay-skin="primary" title="{$vo.name}" {:isset( $group.authority) && in_array($vo.id, $group.authority) ? "checked" : ""}>
                    {/volist}
                {/if}
                <hr>
            {/foreach}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="开启" {if ($group['status'] == 1) } checked {/if}>
            <input type="radio" name="status" value="0" title="禁用" {if ($group['status'] == 0) } checked {/if}>
        </div>
    </div>
</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="button" class="layui-btn" onclick="save()">保存</button>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form'],function(){
        form = layui.form;
        $ = layui.jquery
    });
    function save() {
            $.post("{$config.path}group/edit", $('form').serialize(), function (res) {
                if (res.error_code == 0) {
                    layer.msg(res.msg, { 'icon': 1 });
                    setTimeout(function () {
                        parent.window.location.reload();
                    }, 1000);
                } else {
                    layer.msg(res.msg, { 'icon': 2 });
                }
            }, 'json').error(function (res) {
                layer.msg(res.responseJSON.msg, { 'icon': 2 });
            });
        }
</script>
</body>
</html>